#include <iostream>
#include <vector>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

TreeNode* makeTree(vector<int>& pre, vector<int>& mid, int& head, int left, int right){
    if(left > right) return nullptr;
    if(left == right){
        TreeNode* n = new TreeNode(mid[left]);
        head++;
        return n;
    }
    int rootv = pre[head];
    int rootpos;
    for(int i=left;i<=right;i++){
        if(mid[i] == rootv){
            rootpos = i;
            break;
        }
    }
    TreeNode* root = new TreeNode(rootv);
    head++;
    root->right = makeTree(pre, mid, head, rootpos+1, right);
    root->left = makeTree(pre, mid, head, left, rootpos-1);
    return root;
}

TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {
    vector<int> pre;
    for(int i=postorder.size()-1;i>=0;i--){
        pre.push_back(postorder[i]);
    }
    int head = 0;
    return makeTree(pre, inorder, head, 0, pre.size()-1);
}


int main(){
    cout << "hello world\n";
    return 0;
}